#include <stdlib.h>
#include <thread>
#include <mutex>

#include "lvgl/lvgl.h"

typedef struct {
	volatile bool refr_qry; // 请求更新
	uint32_t tft_fb[DISP_HOR_RES * DISP_VER_RES]; // 一屏缓存
}monitor_t;

typedef struct lvgl_context_t
{
	/* 显示驱动部分 */
	lv_disp_drv_t disp_drv;
	lv_disp_draw_buf_t draw_buf;
	lv_color_t buf1[DISP_HOR_RES * DISP_VER_RES];
	lv_color_t buf2[DISP_HOR_RES * DISP_VER_RES];

	/* 类似指针的设备驱动，如鼠标 */ 
	lv_indev_t* indev_mouse;
	lv_indev_state_t mouse_state;
	lv_point_t mouse_point;
	lv_indev_drv_t mouse_driver;

	lv_indev_t* mousewheel_device_object;
	lv_indev_t* keyboard_device_object;

	//lv_indev_state_t mousewheel_state;
	//int16_t mousewheel_enc_diff;
	//lv_indev_drv_t mousewheel_driver;
} lvgl_context_t;

extern monitor_t g_monitor;  
extern lvgl_context_t g_lvglContext_t;

/* 显示器刷新回调，这里执行显示数据转换，将图像16位转为32位 */
void buffer_trans(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p);

void mouse_read(lv_indev_drv_t* indev, lv_indev_data_t* data);

/* lvgl的硬件抽象层初始化 */
void lvgl_hal_init(void);